modify low_rank for one-body-matrix truncation reference#833
Closed
dogukantai wants to merge 1 commit intoquantumlib:masterfrom
Closed
modify low_rank for one-body-matrix truncation reference#833dogukantai wants to merge 1 commit intoquantumlib:masterfrom
dogukantai wants to merge 1 commit intoquantumlib:masterfrom
Conversation
mpharrigan
requested changes
Aug 18, 2023
| def test_one_body_squared_truncated(self): | ||
| one_body_matrix = numpy.array([[2.0, 1.5, 0.2],[1.5, 3.0, 1.0],[0.2, 1.0, 4.0]]) | ||
| truncation_reference = 1.0 | ||
| with self.assertRaises(ValueError): |
Collaborator
There was a problem hiding this comment.
why is this raising an error? please use assertRaisesRegex to test against (and document) the error message you expect
Comment on lines
+176
to
+177
| truncation_ref (float): Eigenvalues under this threshold reference will | ||
| be truncated for density matrix calculation. |
Collaborator
There was a problem hiding this comment.
document that this is optional and that None turns off truncation
| # If the truncation reference is valid, | ||
| # build truncated eigenvalues and eigenvectors | ||
| # based on the reference for density matrix | ||
| if truncation_ref is not None and isinstance(truncation_ref, float): |
Collaborator
There was a problem hiding this comment.
Let's rely on python duck typing for the type of truncation_ref instead of mandating that it is a float. E.g.: what if it's a np.float64?
| prepare_one_body_squared_evolution(one_body_matrix, | ||
| spin_basis=False) | ||
|
|
||
| def test_one_body_squared_truncated(self): |
Collaborator
There was a problem hiding this comment.
can you add a test that actually works rather then just testing error handling
| retained_indices = numpy.where(eigenvalues < truncation_ref)[0] | ||
| eigenvalues = eigenvalues[valid_indices] | ||
| eigenvectors = eigenvectors[:, valid_indices] | ||
| print(f"Retained {len(valid_indices)} eigenvalues and truncated {len(retained_indices)} eigenvalues from the one-body-matrix.") |
Collaborator
There was a problem hiding this comment.
please do not print in library code
Contributor
|
Closing due to inactivity for 2+ years. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This MR adds eigenvalue truncation parameter according to incomplete TODO for
prepare_one_body_squared_evolutionmethod.